package org.fuxia.im.core;

import java.util.concurrent.ConcurrentHashMap;

import org.fuxia.im.core.iconst.Constant;

/**
 * 抽象上下文类，用于其他上下文类继承
 *
 */
public abstract class AbstractContext
{
	protected ConcurrentHashMap<Object, Object>	context;

	public Object get(Object key)
	{
		return context.get(key);
	}

	public Object put(Object key , Object value)
	{
		return context.putIfAbsent(key, value);
	}

	public Object get(Constant key)
	{
		return this.get(key.name());
	}

	@SuppressWarnings("unchecked")
	public <T> T get(Object key , Class<T> clazz)
	{
		Object o = context.get(key);
		return o != null ? (T) o : null;
	}

	public Object remove(Object key) {
		return context.remove(key);
	}

}
